﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZCustomControl.Models;

namespace ZCustomControl.Helpers
{
    public class ViewItemModelHelper
    {
        /// <summary>
        /// 获取根节点及根节点下的所有节点列表
        /// </summary>
        /// <param name="rootNodes"></param>
        /// <returns></returns>
        public static List<ViewItemModel> GetAllTreeNode(ViewItemModel rootNode)
        {
            List<ViewItemModel> allViewItemList = new List<ViewItemModel>();
            if (rootNode == null)
            {
                return allViewItemList;
            }

            allViewItemList.Add(rootNode);
            allViewItemList.AddRange(GetAllSubTreeNode(rootNode));

            return allViewItemList;
        }

        /// <summary>
        /// 递归获得给定节点的所有级子节点(不包含给定节点本身)
        /// </summary>
        /// <param name="parentNode"></param>
        /// <returns></returns>
        public static List<ViewItemModel> GetAllSubTreeNode(ViewItemModel parentNode)
        {
            List<ViewItemModel> treeModels = new List<ViewItemModel>();
            if (parentNode == null)
            {
                return treeModels;
            }

            foreach (var item in parentNode.Children)
            {
                treeModels.Add(item);
                treeModels.AddRange(GetAllSubTreeNode(item));
            }

            return treeModels;
        }
    }
}
